﻿using Ledict.ConditionExtract.BLL;
using Ledict.Utility.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm
{
    public partial class Analysis : Form
    {
        readonly Express_SourceBLL SourceBLL = new Express_SourceBLL();
        string ccID = string.Empty;
        public Analysis(string ccid)
        {
            InitializeComponent();
            ccID = ccid;
        }

        private void Analysis_Load(object sender, EventArgs e)
        {
            ShowSource(ccID);//显示来源
            webBrowser1.Url = null;//正则
        }

        /// <summary>
        /// 显示来源列表
        /// </summary>
        /// <param name="CC_ID"></param>
        private void ShowSource(string CC_ID)
        {
            GV_Source.AutoGenerateColumns = false;
            GV_Source.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            var dt = SourceBLL.GetSource(CC_ID);

            dt.Columns.Add("RelationSource", typeof(string));
            dt.Columns.Add("CheckRow", typeof(bool));

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i][dt.Columns.Count - 2] = SourceBLL.GetRelationSource(dt.Rows[i]["CC_RegexInfoCode"].ToString(), dt.Rows[i]["ES_ID"].ToString());
                dt.Rows[i][dt.Columns.Count - 1] = false;
            }
            GV_Source.DataSource = dt;
        }

        private void GV_Source_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (GV_Source.Rows[e.RowIndex].Cells["EI_ID"].Value != null)
                {
                    var EI_ID = GV_Source.Rows[e.RowIndex].Cells["EI_ID"].Value.ToString();
                    if (EI_ID != "")
                    {
                        Random rd = new Random();
                        webBrowser1.Url = new Uri(ConfigHelper.AppSettings("RegexSystemUrl") + "/RegexEdit.aspx?EIID=" + EI_ID + "&a=" + rd.Next(10000, 20000));
                    }
                    else
                    {
                        webBrowser1.Url = null;
                    }
                }
            }
        }
    }
}
